﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.Windsor;

namespace ComDevFx.Arch.Base.DI
{
    /// <summary>
    /// Service集成服务
    /// </summary>
    public sealed class ServiceHub : ServiceContainer
    {
        private ServiceHub()
        { }

        static readonly ServiceHub _instance = new ServiceHub();

        public static ServiceHub Instance
        {
            get
            {
                return _instance;
            }
        }

        public T GetService<T>()
        {
            /*
                1.获取WindsorContainer单件实例[如果不想每次都从新这样写，
                可以把WinsdorContainer所在的ServiceContainer做为一个单件关联到ServiceHub中]
             */
            IWindsorContainer container = GetWindsorContainer();

            //返回获取的Service实例
            return container.Resolve<T>();
        }
    }
}
